package com.esun.payment_api.service.impl;

import com.esun.common.utils.BlankUtils;
import com.esun.payment_api.domain.*;
import com.esun.payment_api.mapper.SysCustomerMapper;
import com.esun.payment_api.mapper.SysDictCustomerMapper;
import com.esun.payment_api.mapper.SysDictDataMapper;
import com.esun.payment_api.service.SysDictCustomerService;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("SysDictCustomerService")
public class SysDictCustomerServiceImpl implements SysDictCustomerService {

    @Resource
    SysDictCustomerMapper sysDictCustomerMapper;

    @Resource
    SysCustomerMapper sysCustomerMapper;

    @Resource
    SysDictDataMapper sysDictDataMapper;

    @Override
    public List<SysDictCustomer> selectByExample(Short coId, String keyword, String word) {
        PageHelper.startPage(1, 10);
        SysDictCustomerExample example = new SysDictCustomerExample();
        SysDictCustomerExample.Criteria criteria = example.createCriteria();
        //where条件
        criteria.andIsDeletedEqualTo("0");
        if (!BlankUtils.isBlank(coId)) {
            criteria.andCoIdEqualTo(coId);
        }
        if (!BlankUtils.isBlank(keyword) && !BlankUtils.isBlank(word)) {
            switch (keyword) {
                case "code":
                    criteria.andCodeLike("%" + word + "%");
                    break;
                case "name":
                    criteria.andNameLike("%" + word + "%");
                    break;
                case "type":
                    criteria.andTypeLike("%" + word + "%");
                    break;
                default:
                    System.out.println("输入参数有误！");
                    break;
            }
        }
        return sysDictCustomerMapper.selectByExample(example);
    }

    @Override
    public int insertSelective(SysDictCustomer record) {
        return sysDictCustomerMapper.insertSelective(record);
    }

    @Override
    public int deleteById(Short id) {
        return sysDictCustomerMapper.deleteById(id);
    }

    @Override
    public int updateByPrimaryKeySelective(SysDictCustomer record) {
        return sysDictCustomerMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int insertSysCustomerSelective(SysCustomer record) {
        return sysCustomerMapper.insertSelective(record);
    }

    @Override
    public List<SysCustomer> getSysCustomerByName(String name){
        SysCustomerExample example = new SysCustomerExample();
        SysCustomerExample.Criteria criteria = example.createCriteria();
        criteria.andNameEqualTo(name);
        return sysCustomerMapper.selectByExample(example);
    }

    @Override
    public List<SysCustomer> getSysCustomerByCode(String code){
        SysCustomerExample example = new SysCustomerExample();
        SysCustomerExample.Criteria criteria = example.createCriteria();
        criteria.andCodeEqualTo(code);
        return sysCustomerMapper.selectByExample(example);
    }

    @Override
    public List<SysCustomer> getSysCustomerByItin(String itin){
        SysCustomerExample example = new SysCustomerExample();
        SysCustomerExample.Criteria criteria = example.createCriteria();
        criteria.andItinEqualTo(itin);
        return sysCustomerMapper.selectByExample(example);
    }

    @Override
    public List<SysDictData> getCustomerTypeDict(Short companyId){
        SysDictDataExample example = new SysDictDataExample();
        SysDictDataExample.Criteria criteria = example.createCriteria();
        criteria.andDictTypeEqualTo("wldw_type");
        criteria.andIsDeletedEqualTo("0");
        criteria.andStatusEqualTo("1");
        criteria.andCoIdEqualTo(companyId);

        return sysDictDataMapper.selectByExample(example);
    }

}
